package canglang.monitor.cases.dao;

import java.util.*;

import canglang.monitor.core.base.dao.BaseDAO;
import canglang.monitor.core.base.pagination.PaginatedListHelper;
import canglang.monitor.core.base.util.DateUtil;
import canglang.monitor.core.base.util.StringUtil;
import canglang.monitor.cases.model.CaseFourModel;
import canglang.monitor.cases.to.SearchThreeTO;
import canglang.monitor.cases.to.SearchFourTO;

@SuppressWarnings("unchecked")
public class CaseFourDAO extends BaseDAO{
	public  Integer addCaseFour(CaseFourModel caseFourModel){
        String sql="addCaseFour";
        Map map=objectToMap(caseFourModel);
        return (Integer)getSqlMapClientTemplate().insert(sql,map);
    }
	
	public CaseFourModel getCaseFour(int caseFourId){
        String sql="getCaseFour";
        Map map=new HashMap();
        map.put("caseFourId", caseFourId);
        return (CaseFourModel)getSqlMapClientTemplate().queryForObject(sql,map);
    }
	
    public CaseFourModel saveCaseFour(CaseFourModel caseFourModel){
        String sql="saveCaseFour";
        Map map=objectToMap(caseFourModel);
        getSqlMapClientTemplate().update(sql,map);
        return this.getCaseFour(caseFourModel.getCaseFourId());
    }	
	
    public void deleteCaseFour(int caseFourId){
        String sql="deleteCaseFour";
        Map map=new HashMap();
        map.put("caseFourId", caseFourId);
        getSqlMapClientTemplate().delete(sql,map);
    }

    public Integer searchCount(SearchFourTO searchTO) {
        Map map = new HashMap();
        map.put("deptId", searchTO.getDeptId());
        map.put("dateFrom", searchTO.getDateFrom());
        if (searchTO.getDateTo() != null) {
            map.put("dateTo", DateUtil.add(searchTO.getDateTo(), Calendar.DATE, 1));
        }
        map.put("createId", StringUtil.convertEmpty2Null(searchTO.getCreateId()));
        return (Integer) getSqlMapClientTemplate().queryForObject("searchCaseFourCount", map);
    }

    public List searchList(PaginatedListHelper helper, SearchFourTO searchTO) {
        Map map = new HashMap();
        map.put("deptId", searchTO.getDeptId());
        map.put("dateFrom", searchTO.getDateFrom());
        if (searchTO.getDateTo() != null) {
            map.put("dateTo", DateUtil.add(searchTO.getDateTo(), Calendar.DATE, 1));
        }
        map.put("createId", StringUtil.convertEmpty2Null(searchTO.getCreateId()));
        map = constructPaginationMap(helper, map);
        return getSqlMapClientTemplate().queryForList("searchCaseFourList", map);
    }

      public List getCaseFourList(SearchFourTO searchTO) {
        Map map = new HashMap();
        int deptId = searchTO.getDeptId();
        Date dateFrom = searchTO.getDateFrom();
        Date dateTo = searchTO.getDateTo();
        map.put("deptId", deptId);
        map.put("dateFrom", dateFrom);
        if (dateTo != null) {
            map.put("dateTo", DateUtil.add(dateTo, Calendar.DATE, 1));
        }
        return getSqlMapClientTemplate().queryForList("getCaseFourList", map);
    }
}
